fix(astro): Do not inject withSentry into Cloudflare Pages#19558
fix(astro): Do not inject withSentry into Cloudflare Pages#19558
Conversation
size-limit report 📦
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: JSONC regex matches
pages_build_output_dirinside comments- Added line-start anchoring (^\s*) with multiline flag to the JSON/JSONC regex to match the TOML behavior and prevent false positives from commented-out keys in JSONC files.
Or push these changes by commenting:
@cursor push 232e46c4ee
Preview (232e46c4ee)
diff --git a/packages/astro/src/integration/index.ts b/packages/astro/src/integration/index.ts
--- a/packages/astro/src/integration/index.ts
+++ b/packages/astro/src/integration/index.ts
@@ -284,9 +284,9 @@
return /^\s*pages_build_output_dir\s*=/m.test(content);
}
- // Match "pages_build_output_dir" as a JSON key (followed by :)
- // This works for both .json and .jsonc without needing to strip comments
- return /"pages_build_output_dir"\s*:/.test(content);
+ // Match "pages_build_output_dir" as a JSON key (at start of line, ignoring whitespace)
+ // This avoids false positives from comments in .jsonc files (lines starting with //)
+ return /^\s*"pages_build_output_dir"\s*:/m.test(content);
}
return false;
diff --git a/packages/astro/test/integration/cloudflare.test.ts b/packages/astro/test/integration/cloudflare.test.ts
--- a/packages/astro/test/integration/cloudflare.test.ts
+++ b/packages/astro/test/integration/cloudflare.test.ts
@@ -174,9 +174,9 @@
command: 'build',
});
- expect(baseConfigHookObject.updateConfig).toHaveBeenCalledWith(
- { vite: expect.objectContaining({ plugins: ['sentryCloudflareNodeWarningPlugin'] }) },
- );
+ expect(baseConfigHookObject.updateConfig).toHaveBeenCalledWith({
+ vite: expect.objectContaining({ plugins: ['sentryCloudflareNodeWarningPlugin'] }),
+ });
});
it('correctly parses wrangler.jsonc with URLs and comments', async () => {
@@ -206,9 +206,9 @@
command: 'build',
});
- expect(baseConfigHookObject.updateConfig).toHaveBeenCalledWith(
- { vite: expect.objectContaining({ plugins: ['sentryCloudflareNodeWarningPlugin'] }) },
- );
+ expect(baseConfigHookObject.updateConfig).toHaveBeenCalledWith({
+ vite: expect.objectContaining({ plugins: ['sentryCloudflareNodeWarningPlugin'] }),
+ });
});
it('does not show warning for Pages project with wrangler.toml', async () => {
@@ -290,9 +290,9 @@
});
// Check that sentryCloudflareVitePlugin is NOT in any of the calls
- expect(baseConfigHookObject.updateConfig).toHaveBeenCalledWith(
- { vite: expect.objectContaining({ plugins: ['sentryCloudflareNodeWarningPlugin'] }) },
- );
+ expect(baseConfigHookObject.updateConfig).toHaveBeenCalledWith({
+ vite: expect.objectContaining({ plugins: ['sentryCloudflareNodeWarningPlugin'] }),
+ });
});
it('still adds SSR noExternal config for Pages in dev mode', async () => {|
|
||
| // Match "pages_build_output_dir" as a JSON key (followed by :) | ||
| // This works for both .json and .jsonc without needing to strip comments | ||
| return /"pages_build_output_dir"\s*:/.test(content); |
There was a problem hiding this comment.
JSONC regex matches pages_build_output_dir inside comments
Low Severity
The TOML regex uses ^\s* anchoring with the m flag to avoid matching pages_build_output_dir inside # comments, but the JSON/JSONC regex /"pages_build_output_dir"\s*:/ has no such protection. In a .jsonc file, a commented-out key like // "pages_build_output_dir": "./dist" would still match, causing a Workers project to be misidentified as Pages. This would skip the withSentry wrapper, losing async context propagation and per-request isolation. Anchoring the JSON regex to start-of-line (/^\s*"pages_build_output_dir"\s*:/m) would provide equivalent comment safety as the TOML path.
Additional Locations (1)
node-overhead report 🧳Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.
|
8c5293f to
c707de2
Compare



When running on Cloudflare Pages the
withSentryfunction got bundled and wrapped into theindex.js. This actually didn't cause any problems during the runtime, but it just added unnecessary code into the bundle. This removes now the automatic wrapping, which is required for Cloudflare Workers only.By adding the plugin
sentryCloudflareNodeWarningPluginwe also remove tons of warnings like following when building for Cloudflare Pages:Closes #19559 (added automatically)